package src.main.java.org.charset;

import java.io.UnsupportedEncodingException;
import java.sql.SQLOutput;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String data = "a我b";
        byte[] bytes = data.getBytes();//默认是按照平台字符集（UTF-8）进行编码
        System.out.println(Arrays.toString(bytes));

        //按照指定字符集编码
        byte[] gbks = data.getBytes("GBK");
        System.out.println(Arrays.toString(gbks));

        //解码
        String s = new String(bytes);//默认按照UTF-8解码
        System.out.println(s);

        String s1 = new String(gbks);//出现乱码
        System.out.println(s1);
        String s2 = new String(gbks,"GBK");//出现乱码
        System.out.println(s2);
    }
}
